package com.lbssoft.gpsbd.service.impl;

import com.lbssoft.gpsbd.dao.RoleMapper;
import com.lbssoft.gpsbd.model.Role;
import com.lbssoft.gpsbd.model.vo.RoleVo;
import com.lbssoft.gpsbd.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by nczc on 2018/2/21.
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    public RoleMapper roleMapper;

    @Override
    public List<RoleVo> list() {
        return roleMapper.list();
    }

    @Override
    public void add(Role role) {
        roleMapper.add(role);
    }

    @Override
    public void delete(int id) {
        roleMapper.delete(id);
    }

    @Override
    @CacheEvict(value = "permis", key = "'role_'.concat(#roleId.toString())")
    public void addRolePermis(int roleId, int permissionId) {
        roleMapper.addRolePermis(roleId,permissionId);
    }

    @Override
    public void udpate(RoleVo role) {
        roleMapper.update(role);
    }

    @Override
    @CacheEvict(value = "permis", key = "'role_'.concat(#roleId.toString())")
    public void deleteRolePermis(int roleId,String permissionIds) {
        roleMapper.deleteRolePermis(roleId,permissionIds);
    }

    @Override
    public List<Map> getUserByRole(int roleId) {
        return roleMapper.getUserByRole(roleId);
    }

    @Override
    public Role getRoleById(int id) {
        return roleMapper.getRoleById(id);
    }

}
